<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class S_Router extends CI_Router {

	/*
	 * 支持子目录绑定域名^_^
	 */
	public function _validate_request($segments)
	{
		$this->config->load('domain', TRUE, TRUE);
		$domain = $this->config->item('domain');
		
		if ($domain)
		{
			$protocol = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
			$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
			$d = $protocol.'://'.$host;
			if ($d && isset($domain[$d]))
			{
				array_unshift($segments, $domain[$d]);
			}
			elseif ($segments && array_search($segments[0], $domain) && ! file_exists(APPPATH.'controllers/'.$segments[0].'.php'))
			{
				show_404($segments[0]);
			}
		}

		return parent::_validate_request($segments);
	}

}